package com.lzw.mall.admin.controller;


import com.lzw.mall.common.entity.Attachment;
import com.lzw.mall.common.service.IAttachmentService;
import com.lzw.mall.common.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lizhenwei
 * @since 2023-03-18
 */
@Controller
@RequestMapping("/attachment")
public class AttachmentController {

    @Autowired
    private IAttachmentService attachmentService;

    @PostMapping("/upload")
    @ResponseBody
    public ResultVO upload(MultipartFile file){
        return attachmentService.upload(file);
    }

    @PostMapping("/attProduct")
    @ResponseBody
    public void attProduct(String ids,Integer pid){
        attachmentService.updateSource(ids,pid,"product");
    }

    @GetMapping("/attsProduct")
    @ResponseBody
    public List<Attachment> selectAttsProduct(Integer pid){
        return attachmentService.selectList(pid,"product");
    }

    @PostMapping("/delete")
    @ResponseBody
    public ResultVO delete(Integer id){
        return attachmentService.doDeleteById(id);
    }
}
